package com.zbcz.erp.activity

import android.content.Intent
import android.os.Bundle
import android.util.Log
import com.zbcz.erp.adapter.CommonEditFileAdapter
import com.zbcz.erp.adapter.CommonEditFileAdapter.Companion.ADD_FILE_TYPE
import com.zbcz.erp.bean.FileItem
import com.zbcz.erp.databinding.ActivityErpWorkProcessBinding
import com.zbcz.erp.util.DensityUtils
import com.zbcz.erp.util.onSingleClick

class ErpWorkProcessActivity : BaseActivity() {

    private lateinit var mBinding: ActivityErpWorkProcessBinding

    companion object {
        val REQUEST_CODE_OPEN_DOCUMENT = 101
        const val TAG = "ErpWorkProcessActivity"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        mBinding = ActivityErpWorkProcessBinding.inflate(layoutInflater)
        setContentView(mBinding.root)
        super.onCreate(savedInstanceState)
        init()
    }

    private var mFileAdapter: CommonEditFileAdapter? = null

    private fun init() {
        mBinding.clParent.setPadding(
            0,
            DensityUtils.dp2px(this, 48f),
            0,
            0
        )
        mBinding.clTitle.ivCommonBack.onSingleClick {
            finish()
        }
        mBinding.clTitle.tvTitle.text = "ERP工作流"
        mFileAdapter = CommonEditFileAdapter(this)
        mBinding.rcFileList.adapter = mFileAdapter
        mFileAdapter?.apply {
            submitList(listOf(FileItem(null, ADD_FILE_TYPE)))
        }

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE_OPEN_DOCUMENT && resultCode == RESULT_OK) {
            if (data != null) {
                //content://com.android.providers.media.documents/document/document%3A86986
                val fileUri = data.data
                Log.d(TAG, fileUri.toString())
                mFileAdapter?.addData(fileUri)
            }
        }
    }
}
